home *** CD-ROM | disk | FTP | other *** search
- /*****
- * End.c
- *
- * SoundEditor: Copyright (c) 1993 by
- *
- * Motion Works Corp.
- * #130 - 1020 Mainland Street
- * Vancouver, BC
- * (604) 685-9975
- *
- * Author: DMS (21DEC93)
- *
- * End sound effect (SE) component source for Marvin's Modulator
- *
- *****/
-
- #include <MacHeaders>
- #include <QuickTimeComponents.h>
-
- // prototype
-
- pascal ComponentResult _SEWorksOnSelectionOnly( Boolean *answer );
-
- pascal ComponentResult _SEDoEffect( Handle theSound,
- Size *selectionStart, Size *selectionEnd,
- Handle *newSound,
- Size *insertStart, Size *deleteEnd );
-
- static SoundHeaderPtr _GetTheSoundHeader( Handle theSound );
-
-
- /***
- * _SEWorksOnSelectionOnly
- *
- * returns TRUE to signify that it should only be enabled when there is a selection
- *
- ***/
-
- pascal ComponentResult _SEWorksOnSelectionOnly( Boolean *answer )
- {
- *answer = FALSE;
-
- return noErr;
- }
-
-
-
- /***
- * _SEEffect
- *
- * Reverse the selected samples and return a new sound with those samples in it.
- *
- ***/
-
- pascal ComponentResult _SEDoEffect( Handle theSound,
- Size *selectionStart, Size *selectionEnd,
- Handle *newSound,
- Size *insertStart, Size *deleteEnd )
- {
- ComponentResult result = noErr;
- char theSoundState;
- SoundHeaderPtr theSoundHeaderPtr;
-
- theSoundState = HGetState( theSound );
- HLock( theSound );
-
- theSoundHeaderPtr = _GetTheSoundHeader( theSound );
-
- // set selection point to the end
-
- if ( theSoundHeaderPtr->encode == stdSH )
- {
- *selectionStart = *selectionEnd = theSoundHeaderPtr->length - 1;
- }
- else if ( theSoundHeaderPtr->encode == extSH )
- {
- *selectionStart = *selectionEnd
- = ((ExtSoundHeaderPtr)theSoundHeaderPtr)->numFrames;
- }
- else if ( theSoundHeaderPtr->encode == cmpSH )
- {
- *selectionStart = *selectionEnd
- = ((CmpSoundHeaderPtr)theSoundHeaderPtr)->numFrames;
- }
-
- HSetState( theSound, theSoundState );
-
- // don't delete any samples
- *insertStart = *deleteEnd = 0;
-
- // no new sound to insert
- *newSound = NULL;
-
- return result;
- }
-
-
-
- /**
- * _GetSoundHeader
- *
- * Return a pointer to the SoundHeader. The sound handle must be locked
- * while the pointer is in use.
- *
- **/
- static SoundHeaderPtr _GetTheSoundHeader( Handle theSound )
- {
- Ptr sndData = *theSound; // it's locked by now
- Ptr cmd;
- short numSynth; // should be only one
- short numCmds; // should be only one
- short cmdType;
-
- if ( *((short*)sndData) == 1 ) // format 1
- {
- numSynth = *((short*)(sndData + 2));
- numCmds = *((short*)(sndData + numSynth * 6 + 4)); // 6 bytes per synth + 4 others
- cmd = sndData + numSynth * 6 + 4 + 2;
- }
- else if ( *sndData == 2 ) // format 2
- {
- numCmds = *((short *)(sndData + 4)); // 4 others
- cmd = sndData + 6;
- }
- else
- return NULL;
-
- cmdType = *((short *)cmd) & 0x7FFF;
- if ( cmdType != bufferCmd && cmdType != soundCmd )
- return NULL; // buffer cmd only
-
- return (SoundHeaderPtr)(sndData + *((long*)(cmd + 4))); // param 2 == offset to data
- }
-